home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / russell / russell.lha / examples / self_appl.r < prev    next >
Text File  |  1989-12-29  |  987b  |  48 lines

  1. (* Compile with -p *)
  2. #define L val Short
  3. #define R val Short
  4. #define L_to_R func[L]R
  5.  
  6. (*
  7.  * Applicative Call-by-Value Least Fixed Point
  8.  *)
  9.  
  10. let
  11.     Y == 
  12.             func[ h: func[ L_to_R ] L_to_R ] L_to_R {
  13.                let
  14.                   T == prod{ fn: func[ val T ] L_to_R } ;
  15.  
  16.                   f == func[ v: val T ] L_to_R {
  17.                           h [
  18.                              func[ x: L ] R {
  19.                                 ((fn[v])[v])[x]
  20.                              }
  21.                           ] 
  22.                        }
  23.                in
  24.                   f[T$Mk[f]]
  25.                ni
  26.             } ;
  27.  
  28.          G == 
  29.             func[ f: func[val Short] val Short ] {
  30.                func[ n: val Short ] {
  31.                    if
  32.                      n > 0 ==>
  33.                        n * f[n - 1]
  34.                    # n = 0 ==>
  35.                        1
  36.                    fi
  37.                }
  38.             } ;
  39.  
  40.          ! == Y[G]
  41.  
  42. in
  43.  
  44.       put[6!]; put["\n"]
  45.  
  46. ni
  47.  
  48.